package com.sangmo.fts.api.basic;

import com.sangmo.boot.framework.api.utils.ApiResponse;
import com.sangmo.boot.framework.common.security.meta.Access;
import com.sangmo.boot.framework.data.filter.PageResult;
import com.sangmo.boot.framework.data.filter.PageSearch;
import com.sangmo.fts.basic.interfaces.NoticeCreation;
import com.sangmo.fts.basic.model.Notice;
import com.sangmo.fts.basic.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;

@Controller
@RequestMapping("/notice/v1")
@Access("notice")
public class NoticeApi {

    @Autowired private NoticeService noticeService;

    @Access(":create")
    @PostMapping(value = "/create")
    public @ResponseBody
    ApiResponse<Notice> create(@RequestBody @Valid NoticeCreation obj) {
        return ApiResponse.make(noticeService.create(obj));
    }

    @Access(":read")
    @PostMapping(value = "/search")
    public @ResponseBody
    ApiResponse<PageResult<Notice>> search(@RequestBody @Valid PageSearch pageRequest) {
        return ApiResponse.make(noticeService.search(pageRequest));
    }

}
